//户籍迁出操作按钮
function onFqqyActionRenderer(e) {
    var record1 = e.value;
    var arr = record1.split("@");
    var level = arr[0];
    // 迁移标志
    var state = arr[1];
    var s = "";
    // 司法局,监狱,看守所,社矫中心才能操作
    if (level == '08' || level == '01' || level == '05' || level == '02') {
        // 迁移没有司法局和监狱之分,操作按钮都一样
        // 1:迁移中,4:重新发起迁移
        if (state == "1" || state == "4") {
            // 撤回
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toRevoke(0)"  >&nbsp;&nbsp;撤回&nbsp;&nbsp;</a>&nbsp';
        }
        // 3:迁移失败
        if (state == "3") {
            // 重新发起迁移
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toRelaunch()"  >&nbsp;&nbsp;重新发起&nbsp;&nbsp;</a>&nbsp';
            // 迁移失败原因
            s += '&nbsp;<a class="mini-button mini-button-success"  onclick="toFailureReason()"  >&nbsp;&nbsp;迁移失败原因&nbsp;&nbsp;</a>&nbsp';
            // 删除
            s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="toDelete()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp';
        }
        // 0:待迁移
        if (state == "0") {
            // 重新发起迁移
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toRelaunch()"  >&nbsp;&nbsp;重新发起&nbsp;&nbsp;</a>&nbsp';
            // 删除
            s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="toDelete()"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp';
        }
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="rowdblclick()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//接收迁移操作按钮
function onJsqyActionRenderer(e) {
    var record1 = e.value;
    var arr = record1.split("@");
    var level = arr[0];
    // 迁移标志
    var state = arr[1];
    var s = "";
    // 司法局,监狱,看守所,社矫中心才能操作
    if (level == '08' || level == '01' || level == '05' || level == '02') {
        // 1:迁移中,4:重新发起迁移
        if (state == "1") {
            // 确认迁移
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toConfirmMigration()"  >&nbsp;&nbsp;确认迁移&nbsp;&nbsp;</a>&nbsp';
        }
        if (state == "4") {
            // 再次确认迁移
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toConfirmMigration()"  >&nbsp;&nbsp;再次确认迁移&nbsp;&nbsp;</a>&nbsp';
        }
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="rowdblclick()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//司法局户籍迁移
function toFqqy() {
    mini.open({
        url: "/azbj/transfer/view/addhjqyTab",
        title: "预安置人员迁移",
        width: 720,
        height: 720,
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

//司法所撤回
function toRevoke(state) {
    var row = grid.getSelected();
    mini.confirm("确定撤回该条数据吗？",
        "确定？",
        function (action) {
            if (action == "ok") {
                $.ajax({
                    url: "/azbj/transfer/fqqy/toRevoke?id=" + row.id,
                    type: "post",
                    success: function (success) {
                        if (success.code == 1) {
                            mini.alert("撤回成功");
                        } else if (success.code == 4000) {
                            mini.alert("迁入地已操作,撤回失败")
                        } else if (success.code == 5599) {
                            mini.alert(success.message);
                        } else {
                            mini.alert(mini.alert(success.message));
                        }
                        grid.reload();
                    }
                });
            }
        });
}

/**
 * 复用之前代码
 */
function rowdblclick() {
    //var data = e.record;
    var row = grid.getSelected();
    mini.open({
        // targetWindow: window,
        url: "/azbj/baseInfo/hjqc/toTransferViewTabs/view?priNum=" + row.priNum + "&id=" + row.id,
        title: "查看",
        width: "65%",
        height: "80%",
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

/**
 * 重新发起
 */
function toRelaunch() {
    var row = grid.getSelected();
    mini.open({
        url: "/azbj/transfer/view/addhjqyTab?id=" + row.id,
        title: "再次发起迁移",
        width: 650,
        height: 580,
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

/**
 * 确认迁移按钮/再次确认迁移按钮
 */
function toConfirmMigration() {
    var row = grid.getSelected();
    mini.open({
        url: "/azbj/transfer/view/toConfirmMigration?id=" + row.id,
        title: "确认迁移",
        width: 650,
        height: 580,
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

// toDelete 删除
function toDelete() {
    var row = grid.getSelected();
    mini.confirm("确定删除该条数据吗？",
        "确定？",
        function (action) {
            if (action == "ok") {
                $.ajax({
                    url: "/azbj/transfer/fqqy/toDelete?id=" + row.id,
                    type: "post",
                    success: function (success) {
                        if (4000 == success.code) {
                            mini.alert(success.message);
                        } else if (1 == success.code) {
                            mini.alert("删除成功");
                        } else if (success.code == 5599) {
                            mini.alert(success.message);
                        } else {
                            mini.alert(success.message);
                        }
                        grid.reload();
                    }
                });
            }
        });
}

// toFailureReason 查看迁移失败原因
function toFailureReason() {
    var row = grid.getSelected();
    mini.open({
        url: "/azbj/transfer/fqqy/toFailureReason?id=" + row.id,
        title: "迁移失败原因",
        width: 650,
        height: 580,
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}